<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>菜单编辑</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css" />
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css" />
</head>
<body>
<div class="page-content-wrap">
    <form class="layui-form">
        <div class="layui-tab" style="margin: 0 50px 70px 30px;">
            <div class="layui-tab-content">
                <div class="layui-tab-item"></div>
                <div class="layui-tab-item layui-show">
                    <input type="hidden" class="form-control id" id="id" name="id" value="${sysMenu.id}" />
                    <input type="hidden" class="form-control parentId" id="parentId" name="parentId" value="${sysMenu.parentId}" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级菜单：</label>
                        <div class="layui-input-block">
                            <input type="text" name="parentName" placeholder="" readonly value="${sysMenu.parentName!'主菜单'}" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;菜单类型：</label>
                        <div class="layui-input-block">
                            <select name="menuType" lay-filter="menuType" id="menuType">

                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;菜单名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="menuName" id="menuName" placeholder="请输入菜单名称" value="${sysMenu.menuName}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item menuTypeSelect">
                        <label class="layui-form-label"><span class="red">*</span>请求地址：</label>
                        <div class="layui-input-block">
                            <input type="text" name="menuUrl" id="menuUrl"  placeholder="请输入请求地址" value="${sysMenu.menuUrl}" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>排序：</label>
                        <div class="layui-input-block">
                            <input type="number" name="sort" id="sort"  placeholder="请输入排序" value="${sysMenu.sort}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>备注：</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea" rows="3" style="resize: none" placeholder="请输入备注"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">头像：</label>
                        <!--单图片开始-->
                        <div class="layui-input-block cy-uploadpic-ctn" id="headLogo" style=" float:left;margin-left:0px!important;position:relative;">

                        </div>
                        <!--单图片结束-->
                    </div>


                </div>
            </div>
        </div>
        <div class="layui-form-item layui-pop-btn">
            <div class="">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>

<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery', 'page','dialog','baseutil'], function() {
        var form = layui.form,
            $ = layui.jquery,
            page = layui.page,
            baseutil = layui.baseutil,
            dialog = layui.dialog;
        page.initDict("menu_type",function (dictData) {
            page.showDict($("#menuType"),page.aceeptDictContentList(dictData,"menu_type"),"",'${sysMenu.menuType}');
        });
        if('${sysMenu.menuType}'=="1"){
            $(".menuTypeSelect").hide();
            $(".menuTypeQxSelect").hide();
        }else if('${sysMenu.menuType}'=="3"){
            $(".menuTypeSelect").hide();
        }
        //监听下拉框
        form.on('select(menuType)', function(data){
            debugger
            //1、目录，2、菜单，3、按钮
            if("2"==data.value){
                $(".menuTypeSelect").show();
                $(".menuTypeQxSelect").show();
            }else if("3"==data.value){
                $(".menuTypeSelect").hide();
                $(".menuTypeQxSelect").show();
            }else{
                $(".menuTypeSelect").hide();
                $(".menuTypeQxSelect").hide();
            }
        });
        //监听提交
        form.on('submit(submitBtn)', function(data){
            var menuType=$("#menuType").val();
            var menuName=$("#menuName").val();
            if(menuName == null || menuName == ""){
                dialog.msg("请输入菜单名称");
                return false;
            }
            //1、目录，2、菜单，3、按钮
            if("2"==menuType) {
                var menuUrl = $("#menuUrl").val();
                if (menuUrl == null || menuUrl == "") {
                    dialog.msg("请输入请求地址");
                    return false;
                }
                var permission = $("#permission").val();
                if (permission == null || permission == "") {
                    dialog.msg("请输入权限标识");
                    return false;
                }
            }else if("3"==menuType) {
                var permission = $("#permission").val();
                if (permission == null || permission == "") {
                    dialog.msg("请输入权限标识");
                    return false;
                }
            }
            var sort=$("#sort").val();
            if(sort == null || sort == ""){
                dialog.msg("请输入排序");
                return false;
            }
            baseutil.post("/sysMenu/addOrUpdate",data.field,function (result) {
                if(result.code==0){
                    $("#save").click();
                }else{
                    dialog.msg(result.msg);
                }
            });
            return false;
        });
    });
</script>
</body>

</html>